package com.tgpms.web.excelTable.service.impl;

import com.tgpms.web.excelTable.dao.ExcelColumnMapper;
import com.tgpms.web.excelTable.entity.ExcelColumn;
import com.tgpms.web.excelTable.service.IExcelColumnService;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.UUID;
import java.util.Date;
import com.tgpms.common.Result;
import com.tgpms.exception.ExceptionExplain;
import com.tgpms.util.Common;

/**
 * <p>
 * 动态表格列表 服务实现类
 * </p>
 *
 * @author newway
 * @since 2020-01-17
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, rollbackFor = Exception.class)
public class ExcelColumnServiceImpl implements IExcelColumnService {

	@Resource
	private ExcelColumnMapper mapper;
	
	/**
		新增动态表格列表
	*/
	@Override
	public Result addExcelColumn(ExcelColumn en,Result result) {
		String id = Common.fromDateFormats()+UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
		en.setCId(id);
		en.setRowstamp(id);
		en.setInsertDate(new Date());
		int i = mapper.insert(en);
		if(i==1) {
			result.setMsg(ExceptionExplain.SUCCESS_BY_INSERT.getExplain());
			result.setData(en.getCId());
		}else {
			result.setSuccess(false);
			result.setMsg(ExceptionExplain.ERROR_BY_INSERT.getExplain());
		}
		return result;
	}
	
	/**
		更新动态表格列表
	*/
	@Override
	public Result updateExcelColumn(ExcelColumn en,Result result) {
		int i = mapper.updateById(en);
		if(i==1) {
			result.setMsg(ExceptionExplain.SUCCESS_BY_UPDATE.getExplain());
		}else {
			result.setSuccess(false);
			result.setMsg(ExceptionExplain.ERROR_BY_UPDATE.getExplain());
		}
		return result;
	}
	
	/**
		根据主键删除动态表格列表
	*/
	@Override
	public Result deleteExcelColumn(Serializable id,Result result) {
		int i = mapper.deleteById(id);
		if(i==1) {
			result.setMsg(ExceptionExplain.SUCCESS_BY_DELETE.getExplain());
		}else {
			result.setSuccess(false);
			result.setMsg(ExceptionExplain.ERROR_BY_DELETE.getExplain());
		}
		return result;
	}
}
